package me.zhengjie.modules.business.domain;/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDate;

/**
 * 用户参与到实验中的标签（用户可以不命中实验，因为不是所有流量都会分配到实验中去。当没命中时，也会记录信息（应用+实验+flag为null），避免下次进来时，又给分配进来了。）
 **/
@Entity
@Data
@Table(name="user_flag")
public class UserFlagDO implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "id")
    private Integer id;

    @Column(name = "device_id",nullable = false)
    @ApiModelProperty(value = "机器码")
    private String deviceId;

    @Column(name = "identity_id")
    @ApiModelProperty(value = "唯一识别码")
    private String identityId;

    @Column(name = "app_key")
    @ApiModelProperty(value = "应用key")
    private String appKey;

    @Column(name = "flow_id")
    @ApiModelProperty(value = "流量层ID")
    private int flowID;

    @Column(name = "experiment_key")
    @ApiModelProperty(value = "实验key")
    private String experimentKey;

    @Column(name = "flag_id",nullable = false)
    @ApiModelProperty(value = "变量ID")
    private int flagId;

    @Column(name = "flag_value",nullable = false)
    @ApiModelProperty(value = "变量值")
    private int flagValue;

    @Column(name = "create_time")
    @CreationTimestamp
    @ApiModelProperty(value = "创建时间")
    private Timestamp createTime;

    public void copy(UserFlagDO source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}